home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / math.swg / 0102_Re: Formula for payments.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-22  |  1.6 KB  |  60 lines

  1. (*
  2.  KVR> Hello All,
  3.  KVR> I am busy with a pascal course and I gotta formula I must work out.
  4.  KVR> My maths ended in std 8 so I got noclu of what I'm doin but im doin it
  5.  KVR> anyway!! HELP PLease anybody!!
  6.  KVR> 
  7.  KVR> 12n
  8.  KVR> Ar[1+(r/1200)]
  9.  KVR> P= -----------------------
  10.  KVR> 12n   
  11.  KVR> 1200{[1+(r/1200)]    -1}
  12.  KVR> 
  13.  KVR> This is a formula for monthly mortgage payments.
  14.  KVR> P=repayment value,A=amount borrowed, n=amount of years,
  15.  KVR> r=annual mortgage interest rate.
  16.  KVR> I've done this:
  17.  KVR> 
  18.  KVR> B:=((1+(r/1200))*exp(12*n);
  19.  KVR> P:=((A*r)*B)/(1200*(B-1));
  20.  KVR> and I get some real cockeyed answers 8-)
  21.  
  22. Here you go.  Keep in mind that all variables are of type REAL except the
  23. <n> variable which is type WORD.  Keep in mind that your result is going to
  24. be a real variable, so if you do a writeln(p); you are going to get a really
  25. weird looking answer.  To see it correctly you should use writeln(p:2:2);
  26.  
  27. -----------------------------------/ Cut /------------------------------------
  28. *)
  29.  
  30. Program ShowPayment;
  31. uses crt;
  32.  
  33. var A,P,r:real;
  34.     n:word;
  35.  
  36. function sign(number:real):real;
  37. begin
  38. if number = 0.0 then sign:=1 else sign:=abs(number) / number;
  39. end;
  40.  
  41. function raise(number,power:real):real;
  42. begin
  43. if number =0.0 then
  44.    if power = 0.0 then raise:=1.0 else raise:=0.0
  45. else raise:=sign(number) * exp(power * ln(abs(number)));
  46. end;
  47.  
  48. begin
  49.  
  50.  {P=repayment value,A=amount borrowed, n=amount of years,
  51.  r=annual mortgage interest rate. }
  52.  
  53. A:=2000.0;
  54. r:=10.0;
  55. n:=1;
  56. P:=(A*r*(raise((1.0+(r/1200)),12.0*n)))/(1200.0*(raise((1.0+(r/1200.0)),
  57.         12.0*n)-1.0));
  58. writeln(p:2:2);
  59. end.
  60.